home *** CD-ROM | disk | FTP | other *** search
- Path: ix.netcom.com!netnews
- From: judgemi@ix.netcom.com(Michael Judge )
- Newsgroups: comp.lang.c++
- Subject: Re: new and delete with arrays
- Date: 17 Feb 1996 15:21:32 GMT
- Organization: Netcom
- Message-ID: <4g4rps$h71@ixnews5.ix.netcom.com>
- References: <4g4loa$i1l@mordred.gatech.edu>
- NNTP-Posting-Host: bos-ma10-19.ix.netcom.com
- X-NETCOM-Date: Sat Feb 17 7:21:32 AM PST 1996
-
- In <4g4loa$i1l@mordred.gatech.edu> Darin Heuermann
- <gt1792a@prism.gatech.edu> writes:
- >
- >When I allocate an array of classes with delete, should delete call
- all of
- >the instances' destructors? Here is an example of what I mean.
- >
- >//**********************************************
- >
- >class MYCLASS {
- >public:
- > MYCLASS(void);
- > ~MYCLASS(void);
- >} // MYCLASS
- >
- >MYCLASS *myClass;
- >
- >myClass = new MYCLASS[10];
- >delete myClass;
- >
- >//**********************************************
- >
- >I would expect all 10 instances to call ~MYCLASS() when delete myClass
- is
- >called, but only the first instance's destructor is being called. Is
- the
- >a bug in the compiler or is this how it's supposed to work?
- >
- >-- Darin Heuermann
- >-- Virtual Software
-
- You need to read a book here :)
-
- use delete [] myClass
-
- MJ
- judgemi@ix.netcom.com
-
-